export const dataLayer = dataLayer => {
  return {
    data() {
      return {
        dataLayer
      };
    },
    created() {
      if (!this.dataLayer.components) this.dataLayer.components = {};
      this.dataLayer.components[this.$options.name] = this;
    },
    beforeDestroy() {
      delete this.dataLayer.components[this.name];
    },
    methods: {
      interGet(target, fn) {
        const targetComp = this.dataLayer.components[target];

        return targetComp ? targetComp[fn] : undefined;
      },
      interSet(target, attr, value) {
        const targetComp = this.dataLayer.components[target];
        if (!targetComp) return;
        targetComp[attr] = value;
      }
    }
  };
};
